package com.ljx.GuPiao;

/**
 * @author 李加喜
 * @Package com.ljx.GuPiao
 * @date 2021-11-11 20:52
 */
public class GoodGuPiaoLiRun {
    public static void main(String[] args) {

    }
    public int maxProfit(int[] prices, int fee) {
        int n=prices.length;
        int[][] dp=new int[n][2];
        for (int i=0;i<n;i++){
            if (i-1==-1){
                dp[i][0]=0;
                dp[i][1]=-prices[i]-fee;
                //   dp[i][1]
                // = max(dp[i - 1][1], dp[i - 1][0] - prices[i] - fee)
                // = max(dp[-1][1], dp[-1][0] - prices[i] - fee)
                // = max(-inf, 0 - prices[i] - fee)
                // = -prices[i] - fee
                continue;
            }
            dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1] + prices[i]);
            dp[i][1] = Math.max(dp[i - 1][1], dp[i - 1][0] - prices[i] - fee);
        }
        return dp[n-1][0];
    }
}
